﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;

using MicroCenter.Models;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using Utils.Buffer;

namespace MicroCenter.Tokens
{
    public class AdminToken : AuthIdentity
    {
        public string Password { get; set; }

        public readonly IOptionsMonitor<MicroCenterOptions> optionsMonitor;
        public override bool Deserialize(byte[] data, HttpContext httpContext)
        {
            Password = ByteReadBuffer.Wrap(data).ReadUnknownString();
            if (optionsMonitor.CurrentValue.RootKey.Equals(Password))
            {
                return true;
            }
            return false;
        }

        public override byte[] Serialize()
        {
            var write = ByteWriteBuffer.Alloc();
            write.WriteUnknownString(Password);
            return write.ToBytes();
        }
    }
}
